﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增供应链基础表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SysMaterialGroup",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(24)", maxLength: 24, nullable: true),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterialGroup", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterialGroup_SysMaterialGroup_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysMaterialGroup",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysMeasureUnitGroup",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ErpId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMeasureUnitGroup", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMeasureUnitGroup_SysMeasureUnitGroup_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysMeasureUnitGroup",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysRawMaterial",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    GroupCode = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    UnitCode = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Model = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysRawMaterial", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "SysMeasureUnit",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    MeasureUnitGroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    Level = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMeasureUnit", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMeasureUnit_SysMeasureUnitGroup_MeasureUnitGroupId",
                        column: x => x.MeasureUnitGroupId,
                        principalTable: "SysMeasureUnitGroup",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysMeasureUnit_SysMeasureUnit_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysMeasureUnit",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysMaterial",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    MaterialGroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterial", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterial_SysMaterialGroup_MaterialGroupId",
                        column: x => x.MaterialGroupId,
                        principalTable: "SysMaterialGroup",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysMaterial_SysMeasureUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "SysMeasureUnit",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysMaterialAttribute",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Value = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    IsKeyAttribute = table.Column<bool>(type: "bit", nullable: false),
                    MaterialId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterialAttribute", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterialAttribute_SysMaterial_MaterialId",
                        column: x => x.MaterialId,
                        principalTable: "SysMaterial",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysMaterialSku",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    BarCode = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    TaxPrice = table.Column<decimal>(type: "decimal(28,16)", nullable: false),
                    Price = table.Column<decimal>(type: "decimal(28,16)", nullable: false),
                    LastInStockTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    MaterialId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterialSku", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterialSku_SysMaterial_MaterialId",
                        column: x => x.MaterialId,
                        principalTable: "SysMaterial",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysMaterialSku_SysMeasureUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "SysMeasureUnit",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysMaterialSkuAttributes",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AttributeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    SkuId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterialSkuAttributes", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterialSkuAttributes_SysMaterialAttribute_AttributeId",
                        column: x => x.AttributeId,
                        principalTable: "SysMaterialAttribute",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysMaterialSkuAttributes_SysMaterialSku_SkuId",
                        column: x => x.SkuId,
                        principalTable: "SysMaterialSku",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterial_MaterialGroupId",
                table: "SysMaterial",
                column: "MaterialGroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterial_UnitId",
                table: "SysMaterial",
                column: "UnitId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialAttribute_MaterialId",
                table: "SysMaterialAttribute",
                column: "MaterialId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialGroup_ParentId",
                table: "SysMaterialGroup",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialSku_MaterialId",
                table: "SysMaterialSku",
                column: "MaterialId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialSku_UnitId",
                table: "SysMaterialSku",
                column: "UnitId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialSkuAttributes_AttributeId",
                table: "SysMaterialSkuAttributes",
                column: "AttributeId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialSkuAttributes_SkuId",
                table: "SysMaterialSkuAttributes",
                column: "SkuId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMeasureUnit_MeasureUnitGroupId",
                table: "SysMeasureUnit",
                column: "MeasureUnitGroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMeasureUnit_ParentId",
                table: "SysMeasureUnit",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_SysMeasureUnitGroup_ParentId",
                table: "SysMeasureUnitGroup",
                column: "ParentId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysMaterialSkuAttributes");

            migrationBuilder.DropTable(
                name: "SysRawMaterial");

            migrationBuilder.DropTable(
                name: "SysMaterialAttribute");

            migrationBuilder.DropTable(
                name: "SysMaterialSku");

            migrationBuilder.DropTable(
                name: "SysMaterial");

            migrationBuilder.DropTable(
                name: "SysMaterialGroup");

            migrationBuilder.DropTable(
                name: "SysMeasureUnit");

            migrationBuilder.DropTable(
                name: "SysMeasureUnitGroup");
        }
    }
}
